#!/bin/bash
set -e # set e 遇到非0返回值是会继续向下执行，set -e 非0返回值直接退出

CMAKE_FLAG="-DCMAKE_BUILD_TYPE=Debug"
MAKE=make
NPROC=
ARCH=`arch`

if [ ${ARCH} = "x86_64" ];then
NPROC="-j4"
fi

if [ ! -d "./build" ];then
mkdir -pv build && cd build
else
cd build
fi

if [ -n "$1" ];then
rm -rf *
    case $1 in
    'r') CMAKE_FLAG="-DCMAKE_BUILD_TYPE=Release"
    ;;
    'p') CMAKE_FLAG="-DCMAKE_BUILD_TYPE=Release"
        MAKE="make package"
    ;;
    'c') echo "cross compile"
    esac
fi
echo "cmake ${CMAKE_FLAG} .."
echo "${MAKE}"
cmake ${CMAKE_FLAG} ..
${MAKE} ${NPROC}